package q437;

import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * 437. 路径总和 3
 */
public class Solution {

    int targetSum;
    int pathNum;

    public int pathSum(TreeNode root, int targetSum) {
        this.targetSum = targetSum;
        dfs(root, new LinkedList<>());
        return pathNum;
    }

    public void dfs(TreeNode node, LinkedList<Integer> list) {
        if (node == null) return;
        list.addFirst(node.val);
        long sum = 0;
        for (int i = 0; i < list.size(); i++) {
            sum += list.get(i);
            if (sum == targetSum) {
                pathNum++;
            }
        }
        dfs(node.left, list);
        dfs(node.right, list);
        list.removeFirst();
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public static void main(String[] args) {
        System.out.println(294967296);
    }
}
